package data.set.adaptator;

import java.util.Iterator;

import tools.Pair;

import data.set.OfflineSet;
import data.set.OfflineSetIterator;

public class PairOfflineSet_To_BinaryClassificationOfflineSet_OneAgainstAll<X,Y> implements 
	OfflineSet<Pair<X,Boolean>>
{
	private OfflineSet<Pair<X,Y>> set;
	private Y positive_class;
	
	public PairOfflineSet_To_BinaryClassificationOfflineSet_OneAgainstAll(OfflineSet<Pair<X,Y>> set,Y positive_class)
	{
		this.set=set;
		this.positive_class=positive_class;
	}
	
	
	public Pair<X, Boolean> getObject(int id) {
		boolean c=true;
		Pair<X,Y> v=set.getObject(id);
		
		if (!positive_class.equals(v.getY()))
			c=false;
		return new Pair<X,Boolean>(v.getX(),c);
	}
	
	
	public OfflineSetIterator<Pair<X, Boolean>> inputsetiterator() {
		return(new IT(set.inputsetiterator()));
	}
	
	public long size() {
		return(set.size());
	}
	
	public Iterator<Pair<X, Boolean>> iterator() {
		return(new Iterator_FromOfflineSetIterator<Pair<X,Boolean>>(inputsetiterator()));
	}
	
	private class IT implements OfflineSetIterator<Pair<X,Boolean>>
	{
		private OfflineSetIterator<Pair<X,Y>> it;
		
		public IT(OfflineSetIterator<Pair<X,Y>> it)
		{
			this.it=it;
		}

		public int getCurrentId() {
			return it.getCurrentId();
		}

		
		public Pair<X, Boolean> getCurrentObject() {
			boolean c=true;
			Pair<X,Y> v=it.getCurrentObject();
			
			if (!positive_class.equals(v.getY()))
				c=false;
			return new Pair<X,Boolean>(v.getX(),c);
		}

		
		public boolean hasNext() {
			return it.hasNext();
		}

		
		public void next() {
			it.next();
		}
	}
}
